<#include "header.ftl">
<div style="background-color:#eee; border:solid 1px #ccc; padding:12px; margin-bottom:12px">
${post.getUserName()} said on ${post.getCreateDate()}: 
<h2>${post.getBody()}</h2>
<hr />
Tags:
<#list post.getTags() as tag>
<a href='Home?tag=${tag.getName()}'>#${tag.getName()}</a>(${tag.getCount()}) 
</#list>
<form method="POST">
<input type="text" name="tag" value="add tag" onfocus="this.value=''" onblur="if (this.value=='') this.value='add tag'" />
</form>
</div>

<#if editMode>
	<form method="POST">
		<table class="fields">
		<tr>
			<th>Field Name</th>
			<th>Type</th>
			<th>Mandatory</th>
			<th colspan="2">Extra</th>
		</tr>
		<#list fields as field>
		<tr>
			<td>${field.getLabel()}</td>
			<td>${field.getType()}</td>
			<td><input type="checkbox" disabled="disabled" checked="checked" /></td>
			<td colspan="2">${field.getValuesString()}</td>
		</tr>
		</#list>
		<tr>
			<td><input type="text" name="fieldName" /></td>
			<td>
				<select name="fieldType" onchange="document.getElementById('tbValues').style.display = this.selectedIndex == 5? 'block' : 'none'">
				<#list fieldTypes as ft>
				<option value="${ft.ordinal()}">${ft.toString()}</option>
				</#list>
				</select>
			</td>
			<td><input type="checkbox" /></td>
			<td>
				<input type="text" id="tbValues" name="values" style="display:none" />
			</td>
			<td><input type="submit" value="Add Field" /><a href="?id=${post.getID()}">Return</a></td>
		</tr>
		</table>
	</form>
</#if>
<hr />
<#if !editMode>
	<form method="POST">
	<input type="hidden" name="action" value="addData" />
	<input type="hidden" name="postID" value="${post.getID()}" />
	<table class="fields">
	<#list fields as field>
		<tr>
			<td>${field.getLabel()}</td>
			<td>
			<#if field.getType() == "String">
				<input type="text" name="f_${field.getID()}" />
			<#elseif field.getType() == "Text">
				<textarea name="f_${field.getID()}" class="ta"></textarea>
			<#elseif field.getType() == "Boolean">
				<input type="radio" id="f_${field.getID()}_yes" name="f_${field.getID()}" value="yes" /><label for="id="f_${field.getID()}_yes">YES</label>
				<input type="radio" id="f_${field.getID()}_no" name="f_${field.getID()}" value="no" /><label for="id="f_${field.getID()}_no">NO</label>
			<#elseif field.getType() == "Url">
				<input type="text" name="f_${field.getID()}" value="http://" />
			<#elseif field.getType() == "GeoCode">
				<input type="text" name="f_${field.getID()}" value="0.00000,0.00000" /><button onclick="window.open('http://maps.google.com');return false;">pick</button>
			<#elseif field.getType() == "Selection">
				<select name="f_${field.getID()}">
					<#list field.getValues() as o>
						<option>${o}</option>
					</#list>
				</select>	
			</#if>
			</td>
		</tr>
	</#list>
	<tr>
		<td></td>
		<td><input type="submit" value="Send" />
		<a href="?id=${post.getID()}&mode=edit">Edit Fields</a>
		</td>
	</tr>
	</table>
	</form>
	
	
	<table class="fields">
	<tr>
		<th>User</th>
		<th>Date</th>
		<#list fields as field>
			<th>${field.getLabel()}</th>
		</#list>
	</tr>
	<#list comments as comment>
	<tr>
		<td><a href="Home?userID=${comment.getUserID()}">${comment.getUserName()}</a></td>
		<td>${comment.getCreateDate()}</td>
		<#list comment.getBody() as f>
			<td>${f}</td>
		</#list>
	</tr>
	</#list>
	</table>
</#if>

<#include "footer.ftl">
